package cn.itcast.user.web;

import cn.itcast.user.config.UserProperties;
import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
//@RefreshScope
public class UserController {

    //@Value("${pattern.dateformat}")
    //private String dateformat;

    @Autowired
    private UserService userService;

    @Autowired
    private UserProperties userProperties;

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    //@GetMapping("/{id}")
    //public User queryById(@PathVariable("id") Long id) {
    //    return userService.queryById(id);
    //}

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id, @RequestHeader(value = "Truth",required = false) String truth) {
        System.out.println("truth:"+truth);
        return userService.queryById(id);
    }

    @GetMapping("/value")
    public String testValue(){
        //return dateformat;
        return userProperties.getPattern().getDateformat() + userProperties.getName() + userProperties.getTest();
    }
}
